<!-- Sofija Puric 6/08 -->
<?php
require '../pages/db.php';
$con=dbConnect("sib");
$result=mysql_query("SELECT * FROM reservation", $con);


function change_format_date($date) {
    $new = explode('-',$date);
    $year = $new[0]; $month = $new[1]; $day = $new[2][0].$new[2][1];
    $d = $day.'.'.$month.'.'.$year;
    return $d;
}

echo '
<div class="admin-members">
     <div class="admin-title">
        <h2>Reservations</h2>
    </div>

    <div class="admin-content">
        <table border="0" align="center">
            <thead>
                <tr>
                    <th>Reservation ID</th>
                    <th>User ID</th>
                    <th>Hostel ID</th>
                    <th>Bed number</th>
                    <th>Date From</th>
                    <th>Date To</th>
                    <th>Reservation Date</th>
                    <th>Status</th>
                    <th><p> Change to: &nbsp;</p></th>
                    
                </tr>
            </thead>
            <tbody>';

            while ($row=mysql_fetch_array($result)){
                $from = change_format_date($row["DateFrom"]);
                $to = change_format_date($row["DateTo"]);
                $reservation = change_format_date($row["ReservationDate"]);
            
            echo'
                <tr>
                    <td>'.$row["IDRes"].'</td>
                    <td>'.$row['IDUser'].'</td>
                    <td>'.$row['IDHostel'].'</td>
                    <td>'.$row["NumOfBeds"].'</td>
                    <td>'.$from.'</td>
                    <td>'.$to.'</td>
                    <td>'.$reservation.'</td>
                    <td>'.$row['Status'].'</td>
                    <td><form action="pages/change_reservation_status.php?rid='.$row["IDRes"].'" method="post">

                        <select name="status" size="1">
                        <option value="0">Select...</option>
                        <option value="1">Accepted</option>
                        <option value="2">Denied</option>
                        </select>
                        <button type="submit" class = "button_res">Change!</button>
                   </form></td>
                    <td><a href="reservation-d.php?rid='.$row["IDRes"].'">Delete</a></td>
                </tr>';

                }
            echo'
            </tbody>
        </table>


    </div>

</div>';
?>